package cn.sc.summer.mybatis.strategy.postgresql;

import cn.sc.summer.mybatis.enums.DataSourceTypeEnum;
import cn.sc.summer.mybatis.enums.PostgreSqlJavaTypeEnum;
import cn.sc.summer.mybatis.model.DataSourceColumnType;
import cn.sc.summer.mybatis.table.column.ColumnType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 类名：pgsql字段类型映射
 *
 * @author a-xin
 * @date 2024/8/29 08:47
 */
@Slf4j
@Service
public class PgsqlColumnType implements ColumnType {

    private static final long serialVersionUID = 4226956669138449495L;

    /**
     * 确定该枚举类支持的数据源类型
     *
     * @return 支持的数据源类型
     */
    @Override
    public String supports() {
        return DataSourceTypeEnum.POSTGRESQL.getType();
    }

    /**
     * 获取数据源字段类型
     *
     * @return 数据源字段类型
     */
    @Override
    public List<DataSourceColumnType> getColumnType() {
        List<DataSourceColumnType> dataSourceColumnTypes = new ArrayList<>();
        for (PostgreSqlJavaTypeEnum postgreSqlJavaTypeEnum : PostgreSqlJavaTypeEnum.values()) {
            DataSourceColumnType dataSourceColumnType = new DataSourceColumnType();
            dataSourceColumnType.setDataSourceType(postgreSqlJavaTypeEnum.getDataSourceType());
            dataSourceColumnType.setJavaType(postgreSqlJavaTypeEnum.getJavaType());
            dataSourceColumnType.setPriority(postgreSqlJavaTypeEnum.getPriority());
            dataSourceColumnType.setDefaultLength(postgreSqlJavaTypeEnum.getDefaultLength());
            dataSourceColumnTypes.add(dataSourceColumnType);
        }
        return dataSourceColumnTypes;
    }

}
